package com.ms.demo.demo2;

/**
 * @description: 客户端执行
 * @author: ms
 * @create: 2022-10-28 11:33
 */
public class TestMain {

    public static void main(String[] args) {

        Context context = new Context();
        TerminalExpression e1 = new TerminalExpression();
        TerminalExpression e2 = new TerminalExpression();
        TerminalExpression e3 = new TerminalExpression();
        context.add(e1, 2);
        context.add(e2, 8);
        context.add(e3, 6);

        System.out.println("------------------------------表达式相减操作");
        MinusOperation minusOperation = new MinusOperation(e1, e2);
        System.out.println(minusOperation.interpret(context));

        System.out.println("------------------------------表达式相加操作");
        PlusOperation plusOperation = new PlusOperation(e1,e3);
        System.out.println(plusOperation.interpret(context));

        System.out.println("------------------------------表达式先加再减操作");
        Expression expression = new MinusOperation(new PlusOperation(e1, e2), e3);
        System.out.println(expression.interpret(context));
    }

}